<template>
  <div>
    <div>
      <el-table v-loading="loading" :data="tableData" style="width: 100%">
        <el-table-column prop="createTime" label="创建时间" width="180">
        </el-table-column>
        <el-table-column prop="isPay" label="缴费状态">
          <template slot-scope="scope">
            <span v-if="scope.row.isPay == 1">已缴费</span>
            <span v-else>未缴费</span>
          </template>
        </el-table-column>
        <el-table-column prop="endTime" label="结算时间" width="180">
        </el-table-column>
        <el-table-column prop="totalMoney" label="总金额">
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handlePay(scope.row)"
              v-if="scope.row.isPay != 1">点击缴费</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="block">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { orderList, toPay, listByPatientId } from '../../api/order'

export default {
  name: 'Expense',
  data() {
    return {
      // 遮罩层
      loading: true,
      tableData: [],
      currentPage: 1,
      pageSize: 5,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
      },
      total: null,
      userInfo: null
    }
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      this.userInfo = JSON.parse(localStorage.getItem('userInfo'));
      this.queryParams.patientId = this.userInfo.id;
      listByPatientId(this.queryParams).then(res => {
        this.tableData = res.data.rows;
        this.total = this.tableData.length;
        this.loading = false;
      })
    },
    handleSizeChange(val) {
      this.pageSize = val;
      this.queryParams.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.tableData = [];
      this.currentPage = val;
      this.queryParams.pageNum = val;
      this.getList();
    },
    /** 缴费操作 */
    handlePay(val) {
      toPay(val).then(res => {
        console.log(res);
        if(res.data.code == 200){
          this.$message.success(res.data.msg);
          this.getList();//列表刷新
        }else{
          this.$message.error(res.data.msg);
        }
      });
    }
  }

}
</script>

<style></style>